{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pd.read_csv('../dataset/business.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>categories</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b'Dental by Design'</td>\n",
       "      <td>['Dentists', 'General Dentistry', 'Health &amp; Me...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b'Stephen Szabo Salon'</td>\n",
       "      <td>['Hair Stylists', 'Hair Salons', \"Men's Hair S...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b'Western Motor Vehicle'</td>\n",
       "      <td>['Departments of Motor Vehicles', 'Public Serv...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b'Sports Authority'</td>\n",
       "      <td>['Sporting Goods', 'Shopping']</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>['American (New)', 'Nightlife', 'Bars', 'Sandw...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b'Messina'</td>\n",
       "      <td>['Italian', 'Restaurants']</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>b'BDJ Realty'</td>\n",
       "      <td>['Real Estate Services', 'Real Estate', 'Home ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>b'Soccer Zone'</td>\n",
       "      <td>['Shopping', 'Sporting Goods']</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>b'Any Given Sundae'</td>\n",
       "      <td>['Coffee &amp; Tea', 'Ice Cream &amp; Frozen Yogurt', ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>b'Detailing Gone Mobile'</td>\n",
       "      <td>['Automotive', 'Auto Detailing']</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          name  \\\n",
       "0          b'Dental by Design'   \n",
       "1       b'Stephen Szabo Salon'   \n",
       "2     b'Western Motor Vehicle'   \n",
       "3          b'Sports Authority'   \n",
       "4  b'Brick House Tavern + Tap'   \n",
       "5                   b'Messina'   \n",
       "6                b'BDJ Realty'   \n",
       "7               b'Soccer Zone'   \n",
       "8          b'Any Given Sundae'   \n",
       "9     b'Detailing Gone Mobile'   \n",
       "\n",
       "                                          categories  \n",
       "0  ['Dentists', 'General Dentistry', 'Health & Me...  \n",
       "1  ['Hair Stylists', 'Hair Salons', \"Men's Hair S...  \n",
       "2  ['Departments of Motor Vehicles', 'Public Serv...  \n",
       "3                     ['Sporting Goods', 'Shopping']  \n",
       "4  ['American (New)', 'Nightlife', 'Bars', 'Sandw...  \n",
       "5                         ['Italian', 'Restaurants']  \n",
       "6  ['Real Estate Services', 'Real Estate', 'Home ...  \n",
       "7                     ['Shopping', 'Sporting Goods']  \n",
       "8  ['Coffee & Tea', 'Ice Cream & Frozen Yogurt', ...  \n",
       "9                   ['Automotive', 'Auto Detailing']  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['name','categories']].head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>neighborhood</th>\n",
       "      <th>attributes.DriveThru</th>\n",
       "      <th>attributes.DietaryRestrictions.dairy-free</th>\n",
       "      <th>attributes.DogsAllowed</th>\n",
       "      <th>attributes.RestaurantsDelivery</th>\n",
       "      <th>business_id</th>\n",
       "      <th>attributes.RestaurantsAttire</th>\n",
       "      <th>attributes.CoatCheck</th>\n",
       "      <th>attributes.GoodForMeal.dessert</th>\n",
       "      <th>attributes.GoodForMeal.lunch</th>\n",
       "      <th>...</th>\n",
       "      <th>attributes.Music.jukebox</th>\n",
       "      <th>attributes.GoodForDancing</th>\n",
       "      <th>attributes.RestaurantsReservations</th>\n",
       "      <th>state</th>\n",
       "      <th>attributes.BusinessAcceptsCreditCards</th>\n",
       "      <th>attributes.Alcohol</th>\n",
       "      <th>attributes.DietaryRestrictions.vegetarian</th>\n",
       "      <th>attributes.RestaurantsPriceRange2</th>\n",
       "      <th>attributes.GoodForMeal.breakfast</th>\n",
       "      <th>attributes.Ambience.classy</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b''</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'FYWN1wneV18bWNgQjJ2GNg'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'AZ'</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b''</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'He-G7vWjzVUysIKrfNbPUQ'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'PA'</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b''</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'KQPW8lFf1y5BT2MxiSZ3QA'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'AZ'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b''</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'8DShNS-LuFqpEWIp0HxijA'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>b'AZ'</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b''</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'casual'</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>b'OH'</td>\n",
       "      <td>True</td>\n",
       "      <td>b'full_bar'</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 101 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  neighborhood attributes.DriveThru attributes.DietaryRestrictions.dairy-free  \\\n",
       "0          b''                  NaN                                       NaN   \n",
       "1          b''                  NaN                                       NaN   \n",
       "2          b''                  NaN                                       NaN   \n",
       "3          b''                  NaN                                       NaN   \n",
       "4          b''                False                                       NaN   \n",
       "\n",
       "  attributes.DogsAllowed attributes.RestaurantsDelivery  \\\n",
       "0                    NaN                            NaN   \n",
       "1                    NaN                            NaN   \n",
       "2                    NaN                            NaN   \n",
       "3                    NaN                            NaN   \n",
       "4                    NaN                          False   \n",
       "\n",
       "                 business_id attributes.RestaurantsAttire  \\\n",
       "0  b'FYWN1wneV18bWNgQjJ2GNg'                          NaN   \n",
       "1  b'He-G7vWjzVUysIKrfNbPUQ'                          NaN   \n",
       "2  b'KQPW8lFf1y5BT2MxiSZ3QA'                          NaN   \n",
       "3  b'8DShNS-LuFqpEWIp0HxijA'                          NaN   \n",
       "4  b'PfOCPjBrlQAnz__NXj9h_w'                    b'casual'   \n",
       "\n",
       "  attributes.CoatCheck attributes.GoodForMeal.dessert  \\\n",
       "0                  NaN                            NaN   \n",
       "1                  NaN                            NaN   \n",
       "2                  NaN                            NaN   \n",
       "3                  NaN                            NaN   \n",
       "4                False                          False   \n",
       "\n",
       "  attributes.GoodForMeal.lunch            ...              \\\n",
       "0                          NaN            ...               \n",
       "1                          NaN            ...               \n",
       "2                          NaN            ...               \n",
       "3                          NaN            ...               \n",
       "4                        False            ...               \n",
       "\n",
       "   attributes.Music.jukebox  attributes.GoodForDancing  \\\n",
       "0                       NaN                        NaN   \n",
       "1                       NaN                        NaN   \n",
       "2                       NaN                        NaN   \n",
       "3                       NaN                        NaN   \n",
       "4                     False                      False   \n",
       "\n",
       "  attributes.RestaurantsReservations  state  \\\n",
       "0                                NaN  b'AZ'   \n",
       "1                                NaN  b'PA'   \n",
       "2                                NaN  b'AZ'   \n",
       "3                                NaN  b'AZ'   \n",
       "4                              False  b'OH'   \n",
       "\n",
       "  attributes.BusinessAcceptsCreditCards attributes.Alcohol  \\\n",
       "0                                  True                NaN   \n",
       "1                                  True                NaN   \n",
       "2                                   NaN                NaN   \n",
       "3                                  True                NaN   \n",
       "4                                  True        b'full_bar'   \n",
       "\n",
       "  attributes.DietaryRestrictions.vegetarian attributes.RestaurantsPriceRange2  \\\n",
       "0                                       NaN                               NaN   \n",
       "1                                       NaN                               3.0   \n",
       "2                                       NaN                               NaN   \n",
       "3                                       NaN                               2.0   \n",
       "4                                       NaN                               2.0   \n",
       "\n",
       "  attributes.GoodForMeal.breakfast attributes.Ambience.classy  \n",
       "0                              NaN                        NaN  \n",
       "1                              NaN                        NaN  \n",
       "2                              NaN                        NaN  \n",
       "3                              NaN                        NaN  \n",
       "4                            False                      False  \n",
       "\n",
       "[5 rows x 101 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(174567, 101)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2=pd.read_csv('../dataset/review.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5261669, 9)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "      <th>stars</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b\"Love the staff, love the meat, love the plac...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b\"Super simple place but amazing nonetheless. ...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b\"Small unassuming place that changes their me...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b\"Lester's is located in a beautiful neighborh...</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b\"Love coming here. Yes the place always needs...</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                text  stars\n",
       "0  b\"Love the staff, love the meat, love the plac...      5\n",
       "1  b\"Super simple place but amazing nonetheless. ...      5\n",
       "2  b\"Small unassuming place that changes their me...      5\n",
       "3  b\"Lester's is located in a beautiful neighborh...      5\n",
       "4  b\"Love coming here. Yes the place always needs...      4"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2[['text','stars']].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "five_star=df2[df2['stars']==5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2253348, 9)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "five_star.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "restaurants = df[df['categories'].str.contains('Restaurants')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(54618, 101)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "restaurants.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "restaurants_clean=restaurants[['business_id','name']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>business_id</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b'o9eMRCWt5PkpLDE0gOPtcQ'</td>\n",
       "      <td>b'Messina'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>b'XOSRcvtaKc_Q5H1SAzN20A'</td>\n",
       "      <td>b'East Coast Coffee'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>b'fNMVV_ZX7CJSDWQGdOM8Nw'</td>\n",
       "      <td>b'Showmars Government Center'</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>b'l09JfMeQ6ynYs5MCJtrcmQ'</td>\n",
       "      <td>b'Alize Catering'</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  business_id                           name\n",
       "4   b'PfOCPjBrlQAnz__NXj9h_w'    b'Brick House Tavern + Tap'\n",
       "5   b'o9eMRCWt5PkpLDE0gOPtcQ'                     b'Messina'\n",
       "10  b'XOSRcvtaKc_Q5H1SAzN20A'           b'East Coast Coffee'\n",
       "14  b'fNMVV_ZX7CJSDWQGdOM8Nw'  b'Showmars Government Center'\n",
       "15  b'l09JfMeQ6ynYs5MCJtrcmQ'              b'Alize Catering'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "restaurants_clean.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(54618, 2)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "restaurants_clean.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "combo=pd.merge(restaurants_clean, five_star, on='business_id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1214484, 10)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "combo.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>business_id</th>\n",
       "      <th>name</th>\n",
       "      <th>review_id</th>\n",
       "      <th>text</th>\n",
       "      <th>cool</th>\n",
       "      <th>date</th>\n",
       "      <th>funny</th>\n",
       "      <th>useful</th>\n",
       "      <th>user_id</th>\n",
       "      <th>stars</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>b'fCCL0pAgYGccUs8shHHIUA'</td>\n",
       "      <td>b'I am updating my review to 5-stars because I...</td>\n",
       "      <td>2</td>\n",
       "      <td>b'2015-10-09'</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>b'PixAmdRa58XZ3hr8YLS36g'</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>b'0xKMIkhPVYCSPDA6afn0aw'</td>\n",
       "      <td>b\"This place is AMAZING!! We found it by chanc...</td>\n",
       "      <td>0</td>\n",
       "      <td>b'2016-01-03'</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>b'ajvbqTp1QbKo4pqZmVanYg'</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>b'zorTHqYr_rxVLYgKmlvA6w'</td>\n",
       "      <td>b'One of my favorite  places to eat! Brunch is...</td>\n",
       "      <td>1</td>\n",
       "      <td>b'2015-05-25'</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>b'm0XvqE6XZgqtNulippuVvw'</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>b'sa6lbcuzaMkjVegOT21t8Q'</td>\n",
       "      <td>b\"Been going here for years and it's still my ...</td>\n",
       "      <td>0</td>\n",
       "      <td>b'2017-05-29'</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>b'sXK_eyLpGrNBIAq9fIRGSg'</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b'PfOCPjBrlQAnz__NXj9h_w'</td>\n",
       "      <td>b'Brick House Tavern + Tap'</td>\n",
       "      <td>b'9HPRciMKI0QOVeMtQQs56w'</td>\n",
       "      <td>b'I came here with my brother and the atmosphe...</td>\n",
       "      <td>0</td>\n",
       "      <td>b'2012-11-23'</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>b'OQ_iIzW0c8PoGUcmEr_V7g'</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 business_id                         name  \\\n",
       "0  b'PfOCPjBrlQAnz__NXj9h_w'  b'Brick House Tavern + Tap'   \n",
       "1  b'PfOCPjBrlQAnz__NXj9h_w'  b'Brick House Tavern + Tap'   \n",
       "2  b'PfOCPjBrlQAnz__NXj9h_w'  b'Brick House Tavern + Tap'   \n",
       "3  b'PfOCPjBrlQAnz__NXj9h_w'  b'Brick House Tavern + Tap'   \n",
       "4  b'PfOCPjBrlQAnz__NXj9h_w'  b'Brick House Tavern + Tap'   \n",
       "\n",
       "                   review_id  \\\n",
       "0  b'fCCL0pAgYGccUs8shHHIUA'   \n",
       "1  b'0xKMIkhPVYCSPDA6afn0aw'   \n",
       "2  b'zorTHqYr_rxVLYgKmlvA6w'   \n",
       "3  b'sa6lbcuzaMkjVegOT21t8Q'   \n",
       "4  b'9HPRciMKI0QOVeMtQQs56w'   \n",
       "\n",
       "                                                text  cool           date  \\\n",
       "0  b'I am updating my review to 5-stars because I...     2  b'2015-10-09'   \n",
       "1  b\"This place is AMAZING!! We found it by chanc...     0  b'2016-01-03'   \n",
       "2  b'One of my favorite  places to eat! Brunch is...     1  b'2015-05-25'   \n",
       "3  b\"Been going here for years and it's still my ...     0  b'2017-05-29'   \n",
       "4  b'I came here with my brother and the atmosphe...     0  b'2012-11-23'   \n",
       "\n",
       "   funny  useful                    user_id  stars  \n",
       "0      0       2  b'PixAmdRa58XZ3hr8YLS36g'      5  \n",
       "1      0       0  b'ajvbqTp1QbKo4pqZmVanYg'      5  \n",
       "2      0       0  b'm0XvqE6XZgqtNulippuVvw'      5  \n",
       "3      0       0  b'sXK_eyLpGrNBIAq9fIRGSg'      5  \n",
       "4      0       0  b'OQ_iIzW0c8PoGUcmEr_V7g'      5  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "combo.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "rnn_fivestar_reviews_only=combo[['text']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b'I am updating my review to 5-stars because I...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b\"This place is AMAZING!! We found it by chanc...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>b'One of my favorite  places to eat! Brunch is...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b\"Been going here for years and it's still my ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b'I came here with my brother and the atmosphe...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                text\n",
       "0  b'I am updating my review to 5-stars because I...\n",
       "1  b\"This place is AMAZING!! We found it by chanc...\n",
       "2  b'One of my favorite  places to eat! Brunch is...\n",
       "3  b\"Been going here for years and it's still my ...\n",
       "4  b'I came here with my brother and the atmosphe..."
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rnn_fivestar_reviews_only.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1214484, 1)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rnn_fivestar_reviews_only.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "rnn_fivestar_reviews_only=rnn_fivestar_reviews_only.replace({r'\\n+': ''}, regex=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "final=rnn_fivestar_reviews_only.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1214016, 1)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"<SOR>b'Hummus is amazing and fresh! Loved the falafels. I will definitely be back. Great owner, friendly staff'<EOR>\""
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final['text'][98836]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\hasee\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "#Add start and end of review with <SOR> and <EOR> to each review\n",
    "final['text']='<SOR>' + final['text'].astype(str)+'<EOR>'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>&lt;SOR&gt;b'I am updating my review to 5-stars beca...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;SOR&gt;b\"This place is AMAZING!! We found it by ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;SOR&gt;b'One of my favorite  places to eat! Brun...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;SOR&gt;b\"Been going here for years and it's stil...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;SOR&gt;b'I came here with my brother and the atm...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                text\n",
       "0  <SOR>b'I am updating my review to 5-stars beca...\n",
       "1  <SOR>b\"This place is AMAZING!! We found it by ...\n",
       "2  <SOR>b'One of my favorite  places to eat! Brun...\n",
       "3  <SOR>b\"Been going here for years and it's stil...\n",
       "4  <SOR>b'I came here with my brother and the atm..."
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"<SOR>b'Hummus is amazing and fresh! Loved the falafels. I will definitely be back. Great owner, friendly staff'<EOR>\""
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final['text'][98836]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<SOR>b\"Been going here for years and it\\'s still my favorite place. The servers are friendly and the atmosphere is perfect for any occasion!\"<EOR>'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final.loc[3][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#create a csv of this for future use\n",
    "filename='../dataset/five_star_restaurants_reviews_only.csv'\n",
    "final.to_csv(filename, index=False, encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "#full text file of all reviews to train on\n",
    "filename='../dataset/five_star_text.txt'\n",
    "final.to_csv(filename, header=None, index=None, sep=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "12px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
